package com.easywan.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.easywan.core.SystemDesign;
import com.easywan.dao.ArticleMapper;
import com.easywan.dao.EasywanSystemIndexMapper;
import com.easywan.dao.IBaseDao;
import com.easywan.dao.SpotsMapper;
import com.easywan.dao.WanActiveMapper;
import com.easywan.service.EasywanSystemIndexService;
import com.easywan.util.Utils;
import com.easywan.vo.Article;
import com.easywan.vo.EasywanSystemIndex;
import com.easywan.vo.base.BaseModel;

@Service
public class EasywanSystemIndexServiceImpl extends BaseServiceImpl implements EasywanSystemIndexService{
	private static Logger logger = Logger.getLogger(EasywanSystemIndexServiceImpl.class);
	@Autowired
	private EasywanSystemIndexMapper easywanSystemIndexMapper;
	@Autowired
	private ArticleMapper articleMapper;
	@Autowired
	private SpotsMapper spotsMapper;
	@Autowired
	private WanActiveMapper wanMapper;
	@Override
	public IBaseDao getMapper() {
		// TODO Auto-generated method stub
		return easywanSystemIndexMapper;
	}
	@Override
	public List<EasywanSystemIndex> selectBanner() {
		EasywanSystemIndex temp = new EasywanSystemIndex();
		temp.setName(SystemDesign.INDEX_SLIDER.getValue());
		List<EasywanSystemIndex> results = easywanSystemIndexMapper.select(temp);
		if(Utils.listIsEmpty(results)){
			logger.error("主页banner图出现错误,无法显示主页bnaner");
		}
		return results;
	}
	@Override
	public List<EasywanSystemIndex> selectTj() {
		EasywanSystemIndex temp = new EasywanSystemIndex();
		temp.setName(SystemDesign.INDEX_TJ1.getValue());
		List<EasywanSystemIndex> results = easywanSystemIndexMapper.select(temp);
		if(Utils.listIsEmpty(results)){
			logger.error("主页模块1出现问题");
		}
		return results;
	}
	@Override
	public List<EasywanSystemIndex> selectTj2() {
		EasywanSystemIndex temp = new EasywanSystemIndex();
		temp.setName(SystemDesign.INDEX_TJ2.getValue());
		List<EasywanSystemIndex> results = easywanSystemIndexMapper.select(temp);
		if(Utils.listIsEmpty(results)){
			logger.error("主页模块1出现问题");
		}
		return results;
	}

	@Override
	public List<EasywanSystemIndex> selectByName(String value) {
		EasywanSystemIndex temp = new EasywanSystemIndex();
		temp.setName(value);
		List<EasywanSystemIndex> results = easywanSystemIndexMapper.select(temp);
		if(Utils.listIsEmpty(results)){
			logger.error("主页模块1出现问题");
		}
		return results;
	}
	@Override
	public List<BaseModel> selectByNameMk(String value) {
		List<BaseModel> results = new ArrayList<>();
		EasywanSystemIndex temp = new EasywanSystemIndex();
		temp.setName(value);
		List<EasywanSystemIndex> temps = easywanSystemIndexMapper.select(temp);
		System.out.println(temps);
		try{
			for(EasywanSystemIndex index:temps){
				BaseModel a = null;
				switch(value){
				case "usergl":
					a = spotsMapper.selectByPrimaryColumn(Integer.valueOf(index.getValue1()));
					break;
				case "xiaobiantuijian":
					a = wanMapper.selectByPrimaryColumn(Integer.valueOf(index.getValue1()));
					break;
				default:
					 a = articleMapper.selectByPrimaryColumn(Integer.valueOf(index.getValue1()));
				}
				results.add(a);
			}
		}catch(Exception e){
			logger.error(value+"出现问题!"+e.getMessage());
			e.printStackTrace();
		}
		if(Utils.listIsEmpty(results)){
			logger.error(value+"出现问题,可能原因没有设置！");
		}
		System.out.println(results);
		return results;
	}

}
